package activity;

import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.administrator.ci_edit.R;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import okhttp3.Call;

/**
 * Created by mary on 2017/7/13.
 */

public class RegisteRActivity extends Activity {
    Button button4;
    EditText password1,password2,text;
    String pass1,pass2,text1;

    private String path="http://192.168.154.211:8080/LoginTest/register";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.register);
        button4 =( Button)findViewById(R.id.button4);
        password1 =( EditText)findViewById(R.id.editText2);
        password2 = (EditText)findViewById(R.id.editText3);
        text =( EditText)findViewById(R.id.editText);
        button4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                pass1 = password1.getText().toString();
                pass2 = password2.getText().toString();
                text1 = text.getText().toString();
                if (TextUtils.isEmpty(pass1) || TextUtils.isEmpty(pass2)) {
                    Toast.makeText(RegisteRActivity.this, "账号或密码不能为空", Toast.LENGTH_SHORT).show();
                } else if (!pass2.equals(pass1)) {
                    Toast.makeText(RegisteRActivity.this, "请确认您输入了正确的密码", Toast.LENGTH_SHORT).show();
                } else {
                    OkHttpUtils.post()
                            .url(path)
                            .addParams("username", text1)
                            .addParams("password", pass1)
                            .build()
                            .execute(new StringCallback() {
                                @Override
                                public void onError(Call call, Exception e, int id) {

                                }

                                @Override
                                public void onResponse(String response, int id) {
                                    Toast.makeText(RegisteRActivity.this,"sda",Toast.LENGTH_SHORT).show();
                                }
                            });

                }
            }
        });

    }

}
